package com.sc.nft.util;

import com.sc.nft.exception.GlobalRunTimeException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.List;

/**
 * @author liGen
 * @version 1.0
 * @date 2023/10/24 2:44 下午
 */
public class QAssert {


    /**
     * 校验validate
     *
     * @param bindingResult
     */
    public static void validBindResult(BindingResult bindingResult) {
        if (!bindingResult.hasErrors()) {
            return;
        }
        List<ObjectError> list = bindingResult.getAllErrors();
        String msg = "";
        for (ObjectError errr : list) {
            if (StringUtils.isNotBlank(msg)) {
                msg += ";";
            }
            msg += errr.getDefaultMessage();
        }
        throw new GlobalRunTimeException(msg);
    }
}
